/**
 * 
 */
package net.fancy.util;

import java.util.HashMap;
import java.util.List;

import net.fancy.main.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

/**
 * @author fancylou
 *
 */
public class ClockAdapter extends BaseAdapter {

	private LayoutInflater mInflater;  
    private List<HashMap<String, Object>> list;  
    private int layoutID;  
    
    
    private View myview;
    
    
    public ClockAdapter(Context context, List<HashMap<String, Object>> list,  
            int layoutID) {
		// TODO Auto-generated constructor stub
    	this.mInflater = LayoutInflater.from(context);  
        this.list = list;  
        this.layoutID = layoutID;  
         
	}
	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		myview =  mInflater.inflate(layoutID, null);  
		final TextView title = (TextView) myview.findViewById(R.id.ItemTitle);
		title.setText((String)list.get(position).get("ItemTitle"));
		final TextView content = (TextView) myview.findViewById(R.id.ItemContent);
		content.setText((String)list.get(position).get("ItemContent"));
		final CheckBox cbox = (CheckBox) myview.findViewById(R.id.ItemCheck);
		if((position%2)==0){
			cbox.setChecked(true);
		}else{
			cbox.setChecked(false);
		}
		cbox.setFocusable(false);
		cbox.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(cbox.isChecked()){
					title.setTextColor(0xFFFFFFFF);
					content.setTextColor(0xFFFFFFFF);
				}else{
					title.setTextColor(0x300000FF);
					content.setTextColor(0x30FF0000);
				}
				
				
			}
		});
		return myview;
	}

}
